package com.sunlands.zlcx.usercenter.vo.share;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.google.common.collect.Lists;
import com.sunlands.zlcx.usercenter.domain.share.UserShareInfoDO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Objects;

@Data
@Builder
@ApiModel(value = "学习分享信息")
public class UserShareInfoVO implements Serializable {

    private static final long serialVersionUID = -3856544861387657634L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @ApiModelProperty(value = "学习id")
    private Long learnId;
    @ApiModelProperty(value = "用户id")
    private Long userId;
    @ApiModelProperty(value = "分享内容")
    private String shareContent;
    @ApiModelProperty(value = "状态 正在学习中:1, 学习结束:2")
    private Integer status;
    @ApiModelProperty(value = "用户头像")
    private String avatarUrl;
    @ApiModelProperty(value = "是否点赞")
    private Boolean ifZan;
    @ApiModelProperty(value = "是否打卡")
    private Boolean ifCard;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date createTime;
    @ApiModelProperty(value = "分享打卡列表")
    private List<UserShareCardVO> userShareCardVOList = Lists.newArrayList();
    @ApiModelProperty(value = "分享点赞列表")
    private List<UserShareZanVO> userShareZanVOList= Lists.newArrayList();

    public static UserShareInfoVO from(UserShareInfoDO userShareInfoDO) {
        return Objects.isNull(userShareInfoDO) ? null : UserShareInfoVO.builder()
                .id(userShareInfoDO.getId())
                .userId(userShareInfoDO.getUserId())
                .createTime(userShareInfoDO.getCreateTime())
                .learnId(userShareInfoDO.getLearnId())
                .shareContent(userShareInfoDO.getShareContent())
                .status(userShareInfoDO.getStatus())
                .build();
    }
}
